home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / Depth lib 1.0 folder.sit / Depth lib 1.0 folder / depth_lib 1.0 ƒ / Shell.c < prev    next >
C/C++ Source or Header  |  1995-12-06  |  5KB  |  241 lines

  1. /********************************************************************************
  2.  
  3.      PROJECT:    clut_fade.ケ
  4.      
  5.      FILE:        shell.c
  6.      
  7.      PURPOSE:    'clut' fading functions
  8.      
  9.      STATUS:        Public Domain Demo.
  10.  
  11.  ********************************************************************************/
  12.  
  13. //=================================    INCLUDES ====================================
  14.  
  15. #include "shell.h"
  16. #include "depth.h"
  17.  
  18. // dialog items
  19. #define    kMillions    2
  20. #define    kThousands    3
  21. #define    k256        4
  22. #define    k16            5
  23. #define    k4            6
  24. #define    k2            7
  25.  
  26. #define    kColor        8
  27. #define    kGray        9
  28.  
  29. //=================================    FUNCTIONS ===================================
  30.  
  31. void init_toolbox(void);
  32. void test_window(void);
  33. void SetRadioItem(DialogPtr dlog, short itemNum, Boolean on);
  34. void DisableDItem(DialogPtr dlog, short itemNum);
  35.  
  36.  
  37. /*********************************** main ***************************************/
  38. extern
  39. void main(void)
  40. {
  41.     init_toolbox();
  42.     test_window();    
  43. }
  44. /*** main ***/
  45.  
  46. /********************************** init_toolbox ********************************/
  47. static
  48. void init_toolbox(void)
  49. {
  50.     MaxApplZone();
  51.     MoreMasters();
  52.     InitGraf(&qd.thePort);
  53.     InitFonts();
  54.     InitWindows();
  55.     InitMenus();
  56.     TEInit();
  57.     InitDialogs(0);
  58.     InitCursor();
  59.     FlushEvents(everyEvent, 0);
  60.     DrawMenuBar();
  61. }
  62. /*** init_toolbox ***/
  63.  
  64. static
  65. void SetRadioItem(DialogPtr dlog, short itemNum, Boolean on)
  66. {
  67. short    iType;
  68. Handle    iHandle;
  69. Rect    iRect;
  70.  
  71.     GetDItem(dlog,itemNum,&iType,&iHandle,&iRect);
  72.     SetCtlValue((ControlHandle)iHandle,on ? 1 : 0);
  73. }
  74.  
  75. static 
  76. void DisableDItem(DialogPtr dlog, short itemNum)
  77. {
  78. short    iType;
  79. Handle    iHandle;
  80. Rect    iRect;
  81.  
  82.     GetDItem(dlog,itemNum,&iType,&iHandle,&iRect);
  83.     HiliteControl((ControlHandle)iHandle,255);
  84. }
  85.  
  86. /********************************** test_window *********************************/
  87. static
  88. void test_window(void)
  89. {
  90.     DialogPtr    d;
  91.     GrafPtr        g;
  92.     short        hit;
  93.     GDHandle    hGD;
  94.     CTabHandle    hCTab;
  95.     ControlHandle theCtl;
  96.     Rect        r;
  97.     short        depthItem;
  98.     short        newDepthItem;
  99.     short        newDepth;
  100.     short        modeItem;
  101.     short        newModeItem;
  102.     short        newMode;
  103.     
  104.     if (d = GetNewDialog(128, nil, (WindowPtr) -1L))
  105.     {
  106.         GetPort(&g);
  107.         SetPort(d);
  108.         
  109.         // find the maximum depth of main monitor, and disable radio items.
  110.         switch (MaxScreenDepth(GetMainDevice()))
  111.         {
  112.             case k2Colors:
  113.                 DisableDItem(d,k4);
  114.             case k4Colors:
  115.                 DisableDItem(d,k16);
  116.             case k16Colors:
  117.                 DisableDItem(d,k256);
  118.             case k256Colors:
  119.                 DisableDItem(d,kThousands);
  120.             case kThousandsColors:
  121.                 DisableDItem(d,kMillions);
  122.             case kMillionsColors:
  123.                 break;
  124.         }
  125.         
  126.         // get the current depth and set the appropriate radio item.
  127.         switch(GetScreenDepth(GetMainDevice()))
  128.         {
  129.             case k2Colors:
  130.                 depthItem = k2;
  131.                 break;
  132.             case k4Colors:
  133.                 depthItem = k4;
  134.                 break;
  135.             case k16Colors:
  136.                 depthItem = k16;
  137.                 break;
  138.             case k256Colors:
  139.                 depthItem = k256;
  140.                 break;
  141.             case kThousandsColors:
  142.                 depthItem = kThousands;
  143.                 break;
  144.             case kMillionsColors:
  145.                 depthItem = kMillions;
  146.                 break;
  147.         }
  148.         
  149.         SetRadioItem(d,depthItem,TRUE);
  150.  
  151.         // figure out which modes are supported and disable radio items
  152.         if (!SupportsMode(GetMainDevice(),kColorMode))
  153.             DisableDItem(d,kColor);
  154.         if (!SupportsMode(GetMainDevice(),kGrayMode))
  155.             DisableDItem(d,kGray);
  156.             
  157.         // get current mode and set appropriate radio item
  158.         switch(GetScreenMode(GetMainDevice()))
  159.         {
  160.             case kGrayMode:
  161.                 modeItem = kGray;
  162.                 break;
  163.             case kColorMode:
  164.                 modeItem = kColor;
  165.                 break;
  166.         }
  167.         
  168.         SetRadioItem(d,modeItem,TRUE);
  169.         
  170.         ShowWindow(d);
  171.         
  172.         do
  173.         {
  174.             ModalDialog(nil, &hit);
  175.             switch (hit)
  176.             {
  177.                 // the depth will be changed
  178.                 case k2:
  179.                     newDepthItem = k2;
  180.                     newDepth = k2Colors;
  181.                     goto changeDepth;
  182.                     
  183.                 case k4:
  184.                     newDepthItem = k4;
  185.                     newDepth = k4Colors;
  186.                     goto changeDepth;
  187.                     
  188.                 case k16:
  189.                     newDepthItem = k16;
  190.                     newDepth = k16Colors;
  191.                     goto changeDepth;
  192.                     
  193.                 case k256:
  194.                     newDepthItem = k256;
  195.                     newDepth = k256Colors;
  196.                     goto changeDepth;
  197.                     
  198.                 case kThousands:
  199.                     newDepthItem = kThousands;
  200.                     newDepth = kThousandsColors;
  201.                     goto changeDepth;
  202.                     
  203.                 case kMillions:
  204.                     newDepthItem = kMillions;
  205.                     newDepth = kMillionsColors;                    
  206.                     
  207. changeDepth:        SetRadioItem(d,depthItem,FALSE);
  208.                     depthItem = newDepthItem;
  209.                     SetRadioItem(d,depthItem,TRUE);
  210.                     SetScreenDepth(GetMainDevice(),newDepth);
  211.                     break;
  212.                     
  213.                 // the mode will be changed
  214.                 case kGray:
  215.                     newModeItem = kGray;
  216.                     newMode = kGrayMode;
  217.                     goto changeMode;
  218.                 
  219.                 case kColor:
  220.                     newModeItem = kColor;
  221.                     newMode = kColorMode;
  222.                 
  223. changeMode:            SetRadioItem(d,modeItem,FALSE);
  224.                     modeItem = newModeItem;
  225.                     SetRadioItem(d,modeItem,TRUE);
  226.                     SetScreenMode(GetMainDevice(),newMode);
  227.                     break;
  228.                     
  229.                 default:
  230.                     break;
  231.             }
  232.         }
  233.         while (hit != 1);
  234.         
  235.         SetPort(g);
  236.         DisposDialog(d);
  237.     }
  238. }
  239. /*** test_window ***/
  240.  
  241. //===================================== EOF =====================================